<template>
    <div>
      <el-form :model="registerForm" :rules="rules" class="login-container" label-position="left" label-width="0px" ref="registerForm">
        <!--<h3 class="login_title">login</h3>-->
        <div class="m-logo">
          <img src="https://vuejs.org/images/logo.png">
        </div>
        <el-form-item prop="username">
          <el-input type="text" v-model="registerForm.username" auto-complete="off" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item prop="email">
          <el-input type="text" v-model="registerForm.email" auto-complete="off" placeholder="邮箱"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="registerForm.password" auto-complete="off" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item style="width: 100%">
          <el-button type="primary"  @click="submitForm()" style="width: 100%">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
export default {
  name: 'Register',
  data () {
    return {
      registerForm: {
        username: '',
        email: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        email: [
          { type: 'email', required: true, message: '请输入格式正确的邮箱', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    submitForm () {
      this.$refs.registerForm.validate((valid) => {
        if (valid) {
          console.log('success submit!')
          this.$axios.post('/register', this.registerForm).then(response => {
            this.$router.push('/login')
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
  /*logo图片样式*/
  .m-logo img{
    width: 68px;
    padding-left: 133px;
    padding-bottom: 20px;
  }
  /*登录表单容器样式*/
  .login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 120px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
</style>
